function pwdProtect(pwd, maxLen, minLen){
	var strList3ch = ['01234567890','09876543210','abcdefghijklmnopqrstuvwxyz'];
	var strList5ch = ['qwertyuiop','poiuytrewq',
						'asdfghjkl','lkjhgfdsa',
						'zxcvbnm','mnbvcxz'];
	var strListInvalidWord = ['password'];
	var matchStr;
	var reStr;
	
	//at least 6 characters
	if(pwd.length < minLen){
		return "Err01";
	}
	//at most 20 characters
	if(pwd.length > maxLen){
		return "Err02";
	}
	//pattern
	if(!/^[A-Za-z0-9]+$/.test(pwd)){
		return "Err03";
	}
	//at least one numeric and at least one alphabetic character
	if(!/\d+/.test(pwd) || !/[a-z]+/i.test(pwd)){
		return "Err03";
	}
	//contains the word 'password'
	for(var i=0; i<strListInvalidWord.length; i++){
		reStr = new RegExp(strListInvalidWord[i],'i');
		if(reStr.test(pwd)){
			return "Err05";
		}
	}
	//has more than two repeated characters
	if(/(.)\1{2,}/.test(pwd)){
		return "Err06";
	}
	
	var halfLen = Math.floor(pwd.length/2);
	
	for(var i=0; i<pwd.length-2;i++){
		//has more than or equals to 50% of the characters the same
		if(pwd.split(pwd[i]).length-1>=halfLen){
			return "Err07";
		}
		//has three or more sequential characters
		matchStr = pwd.substring(i,i+3);
		if(/^[a-z0-9]{3}$/i.test(matchStr)){
			for(var j=0; j<strList3ch.length; j++){
				reStr = new RegExp(matchStr,'i');
				if(reStr.test(strList3ch[j])){
					return "Err08";
				}
			}
		}
		//contains a 5-character sub-string of common keyboard patterns
		matchStr = pwd.substring(i,i+5);
		if(/^[a-z0-9]{5}$/i.test(matchStr)){
			for(var j=0; j<strList5ch.length; j++){
				reStr = new RegExp(matchStr,'i');
				if(reStr.test(strList5ch[j])){
					return "Err09";
				}
			}
		}
	}

	return "000";
}

function numericCodeProtect(numericCode, maxLen, minLen){
	if(numericCode.length > maxLen){
		return "Err02";
	}
	if(numericCode.length < minLen){
		return "Err11";
	}
	if(!/^[0-9]+$/.test(numericCode)){
		return "Err10";
	}
	return "000";
}

function maskEmail(email){
	var strList = email.split('@');
	var emailName = strList[0];
	var emailDomain = strList[1];
	return emailName.substring(0,2) + "****" + emailName.substring(6)+'@'+emailDomain;
}

function maskPhone(phone){
	var len = phone.length;
	if(len>6){
		phone = phone.substring(0,len-4) + "****";
	}else{
		phone = phone.substring(0,4) + "****";		
	}
	return phone;
}

function maskUserName(userName){
	var len = userName.length;
	if(len>16){
		userName = userName.substring(0,13) + "***";
	}else if(len<6){
		userName = userName.substring(0,3) + "***";		
	}else{
		userName = userName.substring(0,len-3) + "***";
	}
	return userName;
}

function setNLSConfig(aInst, keyName, val){
	aInst.i18n[keyName] = val;
}

function checkInput4SOTP(fieldArray,obj,butttonId){
	if(obj.value==''){
		fieldArray[obj.id].isEmpty=true;
	}else{
		fieldArray[obj.id].isEmpty=false;
	}
	if(checkEnableButton4SOTP(fieldArray)){
		$(butttonId).removeClass('disabled');
		$(butttonId).attr('aria-disabled',"false");
	}else{
		$(butttonId).addClass('disabled');
		$(butttonId).attr('aria-disabled',"true");
	}
}

function checkEnableButton4SOTP(fieldArray){
	var enableButton=true;
	for(var elementId in fieldArray){
		var isEmpty=fieldArray[elementId]['isEmpty'];
		if(isEmpty){
			enableButton=false;
			break;
		}
	}
	return enableButton;
}

function revertDimButton4SOTP(fieldArray,butttonId){
	if(fieldArray!=undefined && fieldArray!=null){
		for(var elementId in fieldArray){
			fieldArray[elementId]['isEmpty']=true;
		}
		$(butttonId).addClass('disabled');
		$(butttonId).attr('aria-disabled',"true");
	}
}

function parseJSONString4SOTP(data){	
	var rs = data;
	try{
		data = $.parseJSON(data);
		rs = data.DataOutput;
	}
	catch(err){
		// handle server error parseJSONError
		return rs;
	}
	return rs;				
}

function getUrlParams(){
	var paramObj = {};
	var str = location.search;
	if(str.length > 0 && str[0] === '?'){
		str = str.replace('?','&');
		var re = /&[a-z0-9A-Z]+=/g;
		var tempKeyList = str.match(re);
		if(tempKeyList == null || tempKeyList.length == 0){
			return paramObj;
		}
		var valList = str.split(new RegExp(tempKeyList.toString().replace(/\,/g,'|'))).slice(1);
		for(var i=0; i<tempKeyList.length; i++){
			paramObj[tempKeyList[i].replace(/&|=/g,'')] = decodeURIComponent(valList[i]);
		}
	}
	return paramObj;
}

function encodeSpecialChar(str){
	var rtnStr = str;
	rtnStr = rtnStr.replace(/\+/g, "%2B"); 
	rtnStr = rtnStr.replace(/\&/g, "%26");  
	return rtnStr;
}

function errorMsgMapping4SOTP(errObj, code, aInput){
	if(errObj == null || code == null || aInput == null){
		return null;
	}
	if(!$.isArray(aInput)){
		return null;
	}
	return errObj[code].replace(/~~1/,aInput[0]).replace(/~~2/,aInput[1]).replace(/~~3/,aInput[2]);
}

function pauseFunc(fnName,fnParams){
	var funcName = fnName;
	var funcParams = fnParams||[];
	var hasRun = false;
	return {
		run : function(){
			if(!!hasRun){//one time running only
				funcName = null;
				funcParams = null;
				return ;
			}
			hasRun = true;
			if(funcName == null || funcName == "" || !$.isFunction(this[funcName]) 
				|| funcParams == null || !$.isArray(funcParams)){
				return ;
			}
			this[funcName].apply(this, funcParams);
		}
	}
}

var sotpErrorHandler = {
	message : null,
	errType : null,
	codeRegExp : /^(Err|SE)[0-9]{2}$/
};
sotpErrorHandler.handle = function(that, errInfo, errInput){
	if(this.codeRegExp.test(errInfo)){//errInfo is error code
		var msg = this.getErrorMsg(that.sotpErr, errInfo, errInput);
		this.message = msg || iData.get('i18n').nonSOTPAppMsg;
		this.setBackHandle(errInfo);
	}else{//errInfo is error msg
		this.message = errInfo || that._err['noService'];
		this.setBackHandle(errInput);
	}
	$("#errorPage_error_panel > p").replaceWith("<p>" + this.message + "</p>");
	this.showErrorPage(that);
}
sotpErrorHandler.getErrorMsg = function(errObj, code, aInput){
	if(errObj == null || code == null || aInput == null){
		return null;
	}
	if(!$.isArray(aInput)){
		return null;
	}
	return errObj[code].replace(/~~1/,aInput[0]).replace(/~~2/,aInput[1]).replace(/~~3/,aInput[2]);
}
sotpErrorHandler.setBackHandle = function(infoStr){
	if(/^Err[0-9]{2}$/.test(infoStr) || infoStr=="SE03" || infoStr=="SE06" || infoStr=="backToPre"){
		$("#errorPage_btn_back").removeClass('hidden');
		$("#errorPage_btn_ok").addClass('hidden');
	}else{
		$("#errorPage_btn_back").addClass('hidden');
		$("#errorPage_btn_ok").removeClass('hidden');
	}
}
sotpErrorHandler.showErrorPage = function (that) {
	if(true){
		that.goTo('errorPage');
	}else{
		setTimeout('iFunction.delegate.viewIndex="errorPage"',1000);
		that.hideLoadingMask();
	}
}